package com.jia.leetCode;

import java.util.HashSet;
import java.util.Set;

/**
 * 1496. 判断路径是否相交
 */
public class Pro1496 {
    public boolean isPathCrossing(String path) {
        int x = 0, y = 0;
        Set<String> set = new HashSet<>();
        set.add("00");
        String str ="";
        for(int i = 0; i < path.length(); i++) {
            char c = path.charAt(i);
            if(c == 'N') {
                y += 1;
            }else if(c == 'S') {
                y -= 1;
            }else if(c == 'E') {
                x += 1;
            }else if(c == 'W') {
                x -= 1;
            }
            str = "" + x + y;
            if(set.contains(str)) {
                return true;
            }
            set.add(str);
        }
        return false;
    }
}
